﻿using System.Text.Json;

namespace mei_cs.communication;

public class Message(string cmd, dynamic value)
{
    // ReSharper disable once InconsistentNaming
    public string cmd { get; } = cmd;

    // ReSharper disable once InconsistentNaming
    public dynamic value { get; } = value;

    public static string Serialize(string cmd, dynamic value)
    {
        return JsonSerializer.Serialize(new Message(cmd, value));
    }

    public static Message Deserialize(string msg)
    {
        return JsonSerializer.Deserialize<Message>(msg) ?? new Message("", "");
    }
}